//
//  BaseItemModel.m
//  PublicInfo
//
//  Created by enghou on 2017/12/25.
//  Copyright © 2017年 xyxorigation. All rights reserved.
//

#import "BaseItemModel.h"

@implementation BaseItemModel

-(instancetype)initWithSource:(NSDictionary *)source{
    self = [[self class]yy_modelWithJSON:source];
    return self;
}

-(NSString *)contentForKey:(NSString *)key withSource:(NSDictionary *)source{
    NSString *result = [source valueForKey:key];
    if ([result isKindOfClass:[NSString class]]) {
        return result;
    }else if ([result isKindOfClass:[NSNumber class]]){
        int value = [result intValue];
        return [NSString stringWithFormat:@"%i",value];
    }else{
        return @"";
    }
}

-(CGFloat)floatContentForKey:(NSString *)key withSource:(NSDictionary *)source{
    id result = [source valueForKey:key];
    if ([result isKindOfClass:[NSNumber class]]) {
        return [result floatValue];
    }else if ([result isKindOfClass:[NSString class]]){
        return [result floatValue];
    }
    return 0.0;
}

-(NSString *)intContentForKey:(NSString *)key withSource:(NSDictionary *)source{
    NSString *result = [source valueForKey:key];
    if ([result isKindOfClass:[NSString class]]) {
        return result;
    }else if ([result isKindOfClass:[NSNumber class]]){
        int value = [result intValue];
        return [NSString stringWithFormat:@"%i",value];
    }else{
        return nil;
    }
}

@end
